package com.example.android.ui.register;

import com.example.android.bean.Register;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.schedulers.Schedulers;

public class RegisterPresenter implements RegisterContract.IRegisterPresenter {
    RegisterContract.IRegisterModel registerModel;
    private RegisterContract.IRegisterView registerView;

    public RegisterPresenter(RegisterContract.IRegisterView registerView) {
        this.registerView = registerView;
        registerModel = new RegisterModel();
    }

    @Override
    public void addUser(String userAccount, String userMobile, String userPassword) {
        registerModel.addUser(userAccount, userMobile, userPassword)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<Register>() {
                    @Override
                    public void accept(Register register) throws Throwable {
                        registerView.addUserSuccess(register);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Throwable {
                        registerView.addUserError(throwable);
                    }
                });
    }
}
